<template>
<!-- 顾客注册 -->
  <div>
    <van-field v-model="nickname" label="昵称" placeholder="昵称" />

    <van-field v-model="mobile" label="手机号" placeholder="手机号" />
    <van-field
      v-model="password"
      type="password"
      label="密码"
      placeholder="请输入密码"
    />
    <van-field
      v-model="code"
      center
      clearable
      label="短信验证码"
      placeholder="请输入短信验证码"
    >
      <template #button>
        <van-button size="small" type="primary" @click="smscode"
          >发送验证码</van-button
        >
      </template>
    </van-field>
    <br /><br />

    <van-button type="primary" @click="submit">注册</van-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nickname: "",
      mobile: "",
      password: "",
      code: "",
    };
  },
  methods: {
    smscode: function () {
      this.myaxios(this.weburl + "user/smscode/", "post", this.mobile).then(
        (data) => {
          console.log(data);
          if (data.code == 200) {
            this.$toast.success(data.msg);
          }
        }
      );
    },
    submit: function () {
      if (this.nickname == "") {
        this.$toast.fail("昵称不能为空");
        return false;
      }
      if (this.mobile == "") {
        this.$toast.fail("手机号不能为空");
        return false;
      }
      if (this.password == "") {
        this.$toast.fail("密码不能为空");
        return false;
      }
      if (this.code == "") {
        this.$toast.fail("短信验证码不能为空");
        return false;
      }
      this.myaxios(this.weburl + "user/register/", "post", {
        nickname: this.nickname,
        password: this.password,
        mobile:this.mobile,
        code:this.code
      }).then((data) => {
        console.log("data", data);
        if (data.code == 200) {
          this.$toast.success(data.msg);
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
  },
  created() {},
};
</script>

<style scoped>
@import url("../assets/style.css");
</style>